#ifndef PROXIMITY_SENSOR_COMMON_H
#define PROXIMITY_SENSOR_COMMON_H

#include <stdint.h>
#include <pthread.h>
#include "log_utils.h"

// 接近传感器配置结构体
typedef struct {
    const char *gpio_pin;           // GPIO引脚名称
    const char *sensor_name;        // 传感器名称（用于日志标识）
    const char *log_module;         // 日志模块ID
    const char *log_data_type;      // 日志数据类型
    const char *log_state_type;     // 日志状态类型
} proximity_sensor_config_t;

// 接近传感器状态结构体
typedef struct {
    uint8_t sensor_state;           // 传感器状态：0表示检测到物体(有效)，1表示未检测到(无效) - 低电平有效
    uint32_t timestamp;             // 时间戳
    int error_count;                // 错误计数
    int is_initialized;             // 初始化状态标志
} proximity_sensor_state_t;

// 接近传感器句柄结构体
typedef struct {
    proximity_sensor_config_t config;    // 传感器配置
    proximity_sensor_state_t state;      // 传感器状态
    pthread_mutex_t mutex;               // 互斥锁
    void *gpio_handle;                  // GPIO句柄（使用void*避免循环包含）
    int thread_running;                 // 线程运行标志
} proximity_sensor_handle_t;

// 通用函数声明
int proximity_sensor_init(proximity_sensor_handle_t *handle, const proximity_sensor_config_t *config);
void proximity_sensor_cleanup(proximity_sensor_handle_t *handle);
int proximity_sensor_read_state(proximity_sensor_handle_t *handle);
int proximity_sensor_get_state(proximity_sensor_handle_t *handle, proximity_sensor_state_t *state);
void proximity_sensor_debug_gpio(proximity_sensor_handle_t *handle);
void* proximity_sensor_monitor_thread(void *arg);
void proximity_sensor_stop(proximity_sensor_handle_t *handle);

// 预定义的传感器配置
extern const proximity_sensor_config_t PROXIMITY_SENSOR_1_CONFIG;
extern const proximity_sensor_config_t PROXIMITY_SENSOR_2_CONFIG;

#endif /* PROXIMITY_SENSOR_COMMON_H */ 